package SORT_49;

import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Solution {
	public List<List<String>> groupAnagrams(String[] strs) {
		if (strs.length == 0) {

			return new LinkedList<List<String>>();
		}
		Map<String, List<String>> ans = new HashMap<String, List<String>>();
		for (String s : strs) {
			char[] ca = s.toCharArray();
			Arrays.sort(ca);
			String key=String.valueOf(ca);
			if (!ans.containsKey(key)) {
				ans.put(key, new LinkedList<String>());
			}
			ans.get(key).add(s);
		}
		return new LinkedList(ans.values());

	}
}
